package com.fb.fbvedioplayer;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.MenuItem;
import android.view.View;

import com.fb.fbvedioplayer.CustomView.FBVideoPlayerStandard;

/**
 * <pre>
 *     author : fb
 *     e-mail : 469517834@qq.com
 *     time   : 2018/04/17
 *     desc   : recyclerView中使用视频播放器,且滑动后可得到小视频模式
 * </pre>
 */
public class ActivityRecyclerViewTiny extends AppCompatActivity {

	RecyclerView             recyclerView;
	AdapterRecyclerViewVideo adapterVideoList;

	@Override
	protected void onCreate(@Nullable Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_recyclerview);

		recyclerView = findViewById(R.id.recyclerview);
		recyclerView.setLayoutManager(new LinearLayoutManager(this));

		adapterVideoList = new AdapterRecyclerViewVideo(this);
		recyclerView.setAdapter(adapterVideoList);
		recyclerView.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() {
			@Override
			public void onChildViewAttachedToWindow(View view) {
				FBVideoPlayerStandard.onChildViewAttachedToWindow(view, R.id.videoplayer);
			}

			@Override
			public void onChildViewDetachedFromWindow(View view) {
				FBVideoPlayerStandard.onChildViewDetachedFromWindow(view);
			}
		});

	}

	@Override
	public void onBackPressed() {
		if (FBVideoPlayerStandard.backPress()) {
			return;
		}
		super.onBackPressed();
	}

	@Override
	protected void onPause() {
		super.onPause();
		FBVideoPlayerStandard.releaseAllVideos();
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
			case android.R.id.home:
				finish();
				break;
		}
		return super.onOptionsItemSelected(item);
	}

}
